﻿var initLoader = {
	/*** repository预加载 START ***/
	
	//*************************************
	//* 资源管理系统 -> 资源管理
	//*************************************
	repositoryManageLoader : function(){
		if($("#repositoryManageWrapper").length <= 0){
			loadPage("#wrapper", "repository/repository_manage.html");
			look._APP_INFO_DIC_ARRAY.length == 0 ? getAppInfoDictionaryRequest() : getAppInfoDictionaryCallback.Assay();
			if(look._CDN_INFO_DIC_ARRAY.length == 0){getCDNInfoDictionaryRequest();}
			if(look._AGENT_DIC_ARRAY.length == 0){getAgentDictionaryRequest();}
		}
		
		//[事件]新建资源库
		$("#newSubset").unbind("click").bind("click", function(){
			var $appIdSelect = $("#appIdSelect").val();
			if(!($appIdSelect != "0" && $appIdSelect != "")){look.showInfo.error("请选择一个项目");return false;}
			function getPoperRequest(obj, url, callback){
				var offLeft = obj.offset().left - 697,
					offTop = obj.offset().top - 3;
				$.get(url, function(text){
					$.lookpop({
						left: offLeft,
						top: offTop,
						addClass: "new_repository_poper look_box_corner",
						contentHtml: text
					});
					eval(callback());
				});
			}
			var confirmCreateCallback = function(){
				$(".new_repository_poper").css({border: "0",background: "none"});
				$("#repositoryNameInput").focus();
				$("body").unbind("click");
				$("#choosedAppIdInput").val($("#appIdSelect option:selected").text()).attr("appid", $("#appIdSelect").val());
				publicInit.inputTipStyle(".publisher_label input.text", ".publisher_label tt");
				look._CDN_INFO_DIC_ARRAY.length == 0 ? getCDNInfoDictionaryRequest() : getCDNInfoDictionaryCallback.Assay();
				
				//[事件]新建
				$("#createRepositorySubset").bind("click", function(){
					var name = $.trim($("#repositoryNameInput").val()),
						appid = $("#choosedAppIdInput").attr("appid"),
						device = $.trim($("#deviceSelect").val()),
						cdns = new Array(),
						cdnTypeArray = new Array(),
						svnUrl = $.trim($("#svnAddressInput").val()),
						ifSameType = true;
					$("#cdnCheckbox .selected").each(function(){
						cdns.push($(this).attr("c_id"));
						cdnTypeArray.push($(this).attr("c_t"));
					});
					for(var i = 1; i < cdnTypeArray.length; i++){
						if(cdnTypeArray[i] != cdnTypeArray[i - 1]){ifSameType = false;}
					}
					if(name == ""){look.showInfo.error("资源库名称不能为空");$("#repositoryNameInput").focus();return false;}
					if(svnUrl == ""){look.showInfo.error("SVN地址不能为空");$("#svnAddressInput").focus();return false;}
					if(device == ""){look.showInfo.error("请选择设备");return false;}
					if(cdns.length == 0){look.showInfo.error("请选择CDN");return false;}
					if(!ifSameType){look.showInfo.error("不能同时勾选线上服和测试服");return false;}
					popRight(
						'<div style="width:500px;">' +
						'	<div class="pop_content_word">' +
						'		<span class="pop_content_span pop_warning_icon">确定新增本项资源库？</span>' +
						'	</div>' +
						'	<a href="javascript:" class="a_as_button" id="confirmCreateSubset" style="height:24px;line-height:24px;width:100px;">确定</a>　<a href="javascript:clearPop();" class="a_as_button a_as_gray" style="height:24px;line-height:24px;width:100px;">取消</a>' +
						'</div>', '提醒');
					$("#confirmCreateSubset").focus().unbind("click").bind("click", function(){
						if($(this).hasClass("a_as_disabled")){return false;}
						$(this).addClass("a_as_disabled");
						createRepositoryRequest(name, appid, device, cdns, svnUrl);
					}).parents(".pop_dialog_table").bind("click", function(event){
						event.stopPropagation();
					});
				});
				//[事件]清空
				$("#resetRepositorySubset").bind("click", function(){
					$("#repositoryNameInput, #deviceSelect, #svnAddressInput, #svnUsernameInput, #svnPasswordInput").val("");
					$("#cdnCheckbox .a_as_checkbox").removeClass("selected");
				});
			}
			getPoperRequest($(this), "repository/new_repository_poper.html", confirmCreateCallback);
		});
		
		//[事件]查询
		$("#siftSubset").unbind("click").bind("click", function(){
			var $appIdSelect = $("#appIdSelect").val();
			location.hash = look.setParam([["appid", $appIdSelect]], location.hash);
		});
		if(look.getHashParam("appid") == ""){return false;}
		$("#resultLoader").show();
		getRepositoryListRequest(look.getHashParam("appid"));
	},
	//*************************************
	//* 资源管理系统 -> 资源发布历史
	//*************************************
	repositoryHistoryLoader : function(){
		if($("#repositoryHistoryWrapper").length <= 0){
			loadPage("#wrapper", "repository/repository_history.html");
			look._AGENT_DIC_ARRAY.length == 0 ? getAgentDictionaryRequest() : getAgentDictionaryCallback.AssaySelect();
			look._APP_INFO_DIC_ARRAY.length == 0 ? getAppInfoDictionaryRequest() : getAppInfoDictionaryCallback.Assay();
			if(look._CDN_INFO_DIC_ARRAY.length == 0){getCDNInfoDictionaryRequest();}
			
			$("#repositoryLibraryLoader").show();
			repositoryLibraryRequest($("#appIdSelect").val());
			$("#appIdSelect").unbind("change").bind("change", function(){
				$("#repositoryLibraryLoader").show();
				$("#repositorySelect").hide();
				repositoryLibraryRequest($(this).val());
			});
		}
		//[事件]查询
		$("#siftSubset").unbind("click").bind("click", function(){
			var $appIdSelect = $("#appIdSelect").val(),
				$agentSelect = $("#agentSelect").val();
				$repositorySelect = $("#repositorySelect").val();
			if($repositorySelect == ""){look.showInfo.error("请选择一个资源库");return false;}
			location.hash = look.setParam([["appid", $appIdSelect], ["library", $repositorySelect], ["channel", $agentSelect], ["page", "1"]], location.hash);
		});
		//[事件]对比
		$("#contrastSubset").unbind("click").bind("click", function(){
			var element = $("#repositoryHistoryList tr.selected"),
				selectedNum = element.length,
				selectedArray = new Array();
			if(selectedNum != 2){look.showInfo.error("请选择两条记录来进行对比，点击记录即可选择");return false;}
			element.each(function(i){
				selectedArray.push($(this).attr("h_id"));
			});
			popDiv("repository/contrast_history_poper.html");
			contrastHistoryRequest(selectedArray[0], selectedArray[1]);
		});
		if(!(look.getHashParam("appid") != "" && look.getHashParam("library") != "")){return false;}
		$("#resultLoader").show();
		getRepositoryHistoryRequest(look.getHashParam("appid"), look.getHashParam("library"), look.getHashParam("channel"), look.getHashParam("page"));
	}
	
	/*** repository预加载 START ***/
}